package wyj;

import java.util.Scanner;

public class m{

    private static Scanner in;
    public static void main(String[] args) {
        in = new Scanner(System.in);
        String str=null,time = null;
        while (in.hasNext()) {
            str=in.nextLine();
            if (str.equals("END")) {
                break;
            }
            int sum=0;//$*之间字符的异或值
            String []split=str.split(",");
            if(split[0].equals("$GPRMC")) {
                int end=str.indexOf("*");
                for(int i=1;i<end;i++) {
                    sum^=(int)str.charAt(i);
                }
                sum%=65536;
                Boolean flag=split[2].equals("A");
                Boolean  S=sum==Integer.parseInt(str.substring(end+1),16) ;
                if(S==true&&flag==true) {
                    time=split[1];
                }
            }
        }
        if(time!=null) {
            int h=(Integer.parseInt(time.substring(0, 2))+8)%24;
            String m=time.substring(2, 4);
            String s=time.substring(4, 6);
            if(h<10)	System.out.print("0");
            System.out.print(h+":"+m+":"+s);
        }
    }
}